{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Large Integers in Tables and Autotranslation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "JSON has a problem when integers get larger than 10<sup>16</sup>\n",
    "because JavaScript uses floating point for all its numbers.\n",
    "Most languages, including Python, R, and the JVM languages like Groovy can easily handle integers up to 10<sup>19</sup>,\n",
    "and sometimes larger.\n",
    "\n",
    "Numbers this large are useful for measuring time in nanoseconds, for example.\n",
    "\n",
    "BeakerX table and plot widgets have special support 64-bit and arbitrary precision values.  Run these cells, then over over the columns to see their types."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 64-bit Longs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def millis = 1234567890L\n",
    "def nanos = millis * 1000 * 1000L\n",
    "\n",
    "table = [[time: nanos + 7 * 1, next_time:(nanos + 77) * 1, temp:14.6],\n",
    "         [time: nanos + 7 * 2, next_time:(nanos + 88) * 2, temp:18.1],\n",
    "         [time: nanos + 7 * 3, next_time:(nanos + 99) * 3, temp:23.6]]\n",
    "\n",
    "beakerx.table_with_longs = table\n",
    "table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "// expected result\n",
    "Image(\"../../resources/img/groovy/bigInts/cell1_case1.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## BigNums (arbitrary precision)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def millis = 1987654321g\n",
    "// the \"g\" makes this a bignum, with as many bits as needed\n",
    "def nanos  = millis * 1000 * 1000g\n",
    "\n",
    "table = [[time: nanos + 7 * 1, next_time:(nanos + 77) * 777, temp:3.351],\n",
    "         [time: nanos + 7 * 2, next_time:(nanos + 88) * 888, temp:2.355],\n",
    "         [time: nanos + 7 * 3, next_time:(nanos + 99) * 999, temp:2.728]]\n",
    "\n",
    "beakerx.table_with_big_integers = table\n",
    "table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "// expected result\n",
    "Image(\"../../resources/img/groovy/bigInts/cell2_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Groovy",
   "language": "groovy",
   "name": "groovy"
  },
  "language_info": {
   "codemirror_mode": "groovy",
   "file_extension": ".groovy",
   "mimetype": "",
   "name": "Groovy",
   "nbconverter_exporter": "",
   "version": "2.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
